<?php

/***************************************************strat评价API****************************************************/	
	/**
	 * taobao.traderates.get (搜索评价信息)[专]
	 * 查询评价信息，根据传入的参数来查询具体相关的评价记录。
	 * */
	function TOP_TraderatesGet($userParamArr){
	 		$client = new Client();  
		    setUserParameter($client,$userParamArr);  
		    return returnCallBackPage($client,traderatesGet,'rate'); 
	}
	/**
	 * taobao.traderate.add (新增单个评价) [专] 
	 * 对一笔交易进行评价，能用于单个订单的评价。如果评价的交易是父子订单类型的，必须传入父订单id，和具体的子订单id才能进行评价
	 * */
	function TOP_TraderateAdd($userParamArr){
	 		$client = new Client();  
		    setUserParameter($client,$userParamArr);  
		    return returnCallBackPage($client,traderateAdd); 
	}
	/**
	 * taobao.traderate.list.add (针对父子订单新增批量评价) [专] 
	 * 对父子订单类型的交易进行评价，如果是父子订单就只需传入父订单的id就可以对交易的所有子订单进行评价。 
	 * */
	function TOP_TraderateListAdd($userParamArr){
	 		$client = new Client();  
		    setUserParameter($client,$userParamArr);  
		    return returnCallBackPage($client,traderateListAdd);  
	}  
/***************************************************end评价API****************************************************/		
	/**
	 *  得到买家给商城评价内容
	 * */
	function traderates_get_buyer(){
			$userParamArr = array(
							'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
							'rate_type' =>'get',
							'role'      =>'buyer',
							'page_size' =>40,
					     	'page_no' => ((isset($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1)
				 	 ); 
		    $result =TOP_TraderatesGet( $userParamArr );   
		    if( $result['recordCounts'] > 40 ){ //多于一页的下载
				 	for ($i=0;$i<=$result['recordCounts']/40;$i++ )
					{
						$page=$i+1;
					    $userParamArr = array(
										'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
										'page_size' =>40 , 
										'rate_type' =>'get',
										'role'      =>'buyer', 
								     	'page_no' => $page
				     				);    
						$result1  =TOP_TraderatesGet( $userParamArr ); 
						if( ! is_array($result1['list'])) continue;  
						foreach ( $result1['list'] as $row  ){
							if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						}
					}
				} elseif ( $result[recordCounts]>0 && $result[recordCounts]<=40 ){ //不满一页的下载
					   foreach ( $result['list'] as $row  ){  
					   		if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						 }
				}  
		   
   	}
    /**
	 *  得到卖家给商城评价内容
	 * */
	function traderates_get_seller(){
			$userParamArr = array(
							'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
							'rate_type' =>'get',
							'role'   =>'seller',
							'page_size' =>40,
					     	'page_no' => ((isset($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1)
				 	 ); 
			$result =TOP_TraderatesGet( $userParamArr );   
		    if( $result['recordCounts'] > 40 ){ //多于一页的下载
				 	for ($i=0;$i<=$result['recordCounts']/40;$i++ )
					{
						$page=$i+1;
					    $userParamArr = array(
										'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
										'page_size' =>40 , 
										'rate_type' =>'get',
										'role'   =>'seller',
								     	'page_no' => $page
				     				);    
						$result1  =TOP_TraderatesGet( $userParamArr );   
						foreach ( $result1['list'] as $row  ){
							if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						}
					}
				} elseif ( $result[recordCounts]>0 && $result[recordCounts]<=40 ){ //不满一页的下载
					   foreach ( $result['list'] as $row  ){  
					   		if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						 }
				}  
	}
	/**
	 *  给出买家给商城评价内容
	 * */
	function traderates_give_buyer(){
			 $userParamArr = array(
							'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
							'rate_type' =>'give',
							'role'   =>'buyer',
							'page_size' =>40,
					     	'page_no' => ((isset($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1)
				 	 );  
			$result =TOP_TraderatesGet( $userParamArr );   
		    if( $result['recordCounts'] > 40 ){ //多于一页的下载
				 	for ($i=0;$i<=$result['recordCounts']/40;$i++ )
					{
						$page=$i+1;
					    $userParamArr = array(
										'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
										'page_size' =>40 , 
										'rate_type' =>'give',
										'role'   =>'buyer',
								     	'page_no' => $page
				     				);    
						$result1  =TOP_TraderatesGet( $userParamArr );   
						foreach ( $result1['list'] as $row  ){
							if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						}
					}
				} elseif ( $result[recordCounts]>0 && $result[recordCounts]<=40 ){ //不满一页的下载
					   foreach ( $result['list'] as $row  ){  
					   		if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						 }
				}  
	}
    /**
	 *  给出卖家给商城评价内容
	 * */
	function traderates_give_seller(){
			$userParamArr = array(
							'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
							'rate_type' =>'give',
							'role'   =>'seller',
							'page_size' =>40,
					     	'page_no' => ((isset($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] : 1)
				 	 );  
	        $result =TOP_TraderatesGet( $userParamArr );   
		    if( $result['recordCounts'] > 40 ){ //多于一页的下载
				 	for ($i=0;$i<=$result['recordCounts']/40;$i++ )
					{
						$page=$i+1;
					    $userParamArr = array(
										'fields' => 'tid,oid,role,nick,result,created,rated_nick,item_title,item_price,content,reply',
										'page_size' =>40 , 
										'rate_type' =>'give',
										'role'   =>'seller',
								     	'page_no' => $page
				     				);    
						$result1  =TOP_TraderatesGet( $userParamArr );   
						foreach ( $result1['list'] as $row  ){
							if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						}
					}
				} elseif ( $result[recordCounts]>0 && $result[recordCounts]<=40 ){ //不满一页的下载
					   foreach ( $result['list'] as $row  ){  
					   		if( $row['tid'] && $row['oid'] && Check_is_exist('tb_traderate','tid', $row['tid'], " oid='".$row['oid']."' and role='".$row['role']." "))  continue;
							if( $row['tid'] && Check_is_exist('tb_traderate','tid', $row['tid'],'','id') ) continue;
							if( $row['oid'] )	OS_InsertIntoTB('tb_traderate','tid',$row,"oid='".$row['oid']."' and role='".$row['role']."' and nick='".$row['nick']."'");    
							OS_InsertIntoTB('tb_traderate','tid',$row, "role='".$row['role']."' and nick='".$row['nick']."'");    
						 }
				}  
	}

	

?>